/**
 * @param {number[]} nums
 * @return {void} Do not return anything, modify nums in-place instead.
 * 输入：nums = [2,0,2,1,1,0]
输出：[0,0,1,1,2,2]
 */
var sortColors = function (nums) {
  let red = 0
  let white = 0
  let blue = 0
  let i = 0
  while (i < nums.length) {
    if (nums[i] === 0) {
      nums.unshift(nums.splice(i, 1)[0])
      red++
      white++
      blue++
    } else if (nums[i] === 1) {
      nums.splice(red, 0, nums.splice(i, 1)[0])
      white++
    } else if (nums[i] === 2) {
      nums.splice(white, 0, nums.splice(i, 1)[0])
    }
    i++
  }
  return nums
}
console.log(sortColors([2, 0, 2, 1, 1, 0]))
